package com.lc.cehui.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.imageview.ShapeableImageView;
import com.lc.cehui.R;
import com.lc.cehui.http.glide.GlideApp;
import com.lc.cehui.http.response.MySendsType5Bean;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class ReleaseFragment5Adapter extends RecyclerView.Adapter{
    public static final int TYPE_ONE = 46;
    public static final int TYPE_TWO = 47;
    public static final int TYPE_OTHER = 50;


    private Context context;

    private List<MySendsType5Bean.DataBean> datas;

    public ReleaseFragment5Adapter(Context context, List<MySendsType5Bean.DataBean> datas){
        this.context = context;
        this.datas = datas;

    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        if (viewType == TYPE_ONE||viewType==TYPE_TWO){
            view = View.inflate(context, R.layout.item_zhanhui,null);
            ItemOneViewHolder holder = new ItemOneViewHolder(view);
            holder.titile = view.findViewById(R.id.tv_title);
            holder.img = view.findViewById(R.id.img);
            holder.tv_staut = view.findViewById(R.id.tv_staut);
            holder.tv_date = view.findViewById(R.id.tv_date);
            holder.tv_delete = view.findViewById(R.id.tv_delete);
            holder.rl_type = view.findViewById(R.id.rl_type);
            return  holder;
        }else {
            view = View.inflate(context, R.layout.item_ziyuangongxiang, null);

            ItemTreeViewHolder holder = new ItemTreeViewHolder(view);

            holder.titile = view.findViewById(R.id.tv_title);
            holder.tv_name = view.findViewById(R.id.tv_name);
            holder.img = view.findViewById(R.id.img);
            holder.ll_type = view.findViewById(R.id.ll_type);

            return  holder;

        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ItemOneViewHolder){
            ItemOneViewHolder viewHolder= (ItemOneViewHolder) holder;
            viewHolder.titile.setText(datas.get(position).getTitle());
//            viewHolder.tv_staut.setText(datas.get(position).getStatus());
            viewHolder.tv_date.setText(datas.get(position).getCreate_time());
            GlideApp.with(context).load(datas.get(position).getPicurl())
                    .apply(new RequestOptions().placeholder(R.drawable.image11).error(R.drawable.image11)).into(((ImageView) viewHolder.img));
        }else if (holder instanceof ItemTreeViewHolder){
            ItemTreeViewHolder viewHolder= (ItemTreeViewHolder) holder;
            viewHolder.titile.setText(datas.get(position).getTitle());
//            viewHolder.tv_name.setText(datas.get(position).getTitle());
            GlideApp.with(context).load(datas.get(position).getPicurl())
                    .apply(new RequestOptions().placeholder(R.drawable.image11).error(R.drawable.image11)).into(((ImageView) viewHolder.img));
        }
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }
    @Override
    public int getItemViewType(int position) {
        MySendsType5Bean.DataBean bean = datas.get(position);
        if (bean.getType_id() == TYPE_ONE ){
            return TYPE_ONE;
        }else if (bean.getType_id() == TYPE_TWO){
            return TYPE_TWO;
        }else {
            return TYPE_OTHER;
        }
    }
    public void setData(List<MySendsType5Bean.DataBean> dataList) {
        datas=dataList;
        notifyDataSetChanged();
    }
    class ItemOneViewHolder extends RecyclerView.ViewHolder{
        TextView titile;
        TextView tv_staut;
        TextView tv_date;
        TextView tv_delete;
        RelativeLayout rl_type;
        ShapeableImageView img;
        public ItemOneViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }



    class ItemTreeViewHolder extends RecyclerView.ViewHolder{
        TextView titile;
        TextView tv_name;
        ShapeableImageView img;

        LinearLayout ll_type;
        public ItemTreeViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}
